//
//  CusSearchBarView.swift
//  NewRegProject
//
//  Created by 伊伊 on 2023/2/17.
//

import UIKit

class CusSearchBarView: UIView {
 @objc var  contentSize:CGSize = CGSize.zero
    @objc var searchTypeShow:Bool = false {
        didSet{
            if(searchTypeShow == true){
                self.searchTypeButton.snp.remakeConstraints { make in
                    make.left.equalToSuperview().offset(15)
                    make.top.bottom.equalToSuperview()
                }
                self.searchTypeButton.isHidden = false
                self.leftImageView.snp.remakeConstraints { make in
                    make.left.equalTo(self.searchTypeButton.snp.right).offset(10)
                    make.centerY.equalToSuperview()
                }
            }else{
                self.searchTypeButton.snp.remakeConstraints { make in
                    make.left.equalToSuperview().offset(15).priority(900)
                    make.top.bottom.equalToSuperview()
                }
                self.searchTypeButton.isHidden = true
                
                
                self.leftImageView.snp.remakeConstraints { make in
                    make.left.equalTo(self).offset(10)
                    make.centerY.equalToSuperview()
                }
            }
        }
    }
    @objc var searchTypeButton:HLTContolButton!
    private var leftImageView:UIImageView!
   @objc var clickSearchBlock = {
        () -> () in
    }
    @objc var clickTypeBlock = {
         () -> () in
     }
  @objc  var textFiled:UITextField!
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .white
        let textField = CustomTextFiled()
        self.addSubview(textField)
        textField.marginEdges = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        self.backgroundColor = UIColor(hexString: "F5F5F5")

        textField.placeholder = "请输入商标名称"
       // textField.placeHolderTextColor(color: UIColor(hexString:"666666"), font: kFont(12))
        textField.snp.makeConstraints { make in
            make.top.bottom.right.equalToSuperview()
        }
        textField.font = kFont(13)
        self.textFiled = textField
        self.searchTypeButton = HLTContolButton.layoutLeadingtitle(title: "默认", imageName: "sousuoyemianxiangxiajiantou", axi: .horizontal)
        self.addSubview(self.searchTypeButton)
        self.searchTypeButton.lableFont = kFont(14)
        self.searchTypeButton.spacing = 2;
        self.searchTypeButton.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15).priority(900)
            make.top.bottom.equalToSuperview()
        }
        self.searchTypeButton.isHidden = true
        self.searchTypeButton.lableTextColor = UIColor(red: 170.0 / 255.0, green: 170.0 / 255.0, blue: 170.0 / 255.0, alpha: 1)
        self.searchTypeButton.clickBtn = {  _ in
            self.clickBtn()
        }
        //self.searchTypeButton.addTarget(self, action: #selector(clickBtn), for: .touchUpInside)
        let imageView = UIImageView(image: UIImage(named: "search"))
        self.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.left.equalTo(self).offset(10)
            make.centerY.equalToSuperview()
        }
        self.leftImageView = imageView
        textField.snp.makeConstraints { make in
            make.left.equalTo(imageView.snp.right).offset(5);
        }
    }
    @objc func clickBtn(){
        self.clickTypeBlock()
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        self.clickSearchBlock()
    }
 
//
    override var intrinsicContentSize: CGSize{
        set{}
        get{
            return self.contentSize
        }
    }

    
}
